package cn.catfish;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

import java.awt.*;
import java.net.URI;

@SpringBootApplication
@EnableCaching
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
        String url = "http://localhost:8080/swagger-ui/";
        System.out.println("swagger-ui访问地址：" + url);

        openBrowser(url);

    }
    private static void openBrowser(String url) {
        try {
            if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                Desktop.getDesktop().browse(new URI(url));
            }else {
               Runtime runtime = Runtime.getRuntime();
               String os = System.getProperty("os.name").toLowerCase();
               if (os.contains("win")) {
                     runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
               }else if (os.contains("mac")) {
                     runtime.exec("open " + url);
               }else if (os.contains("nix") || os.contains("nux")) {
                     runtime.exec("xdg-open " + url);
               }else {
                     System.out.println("该系统暂不支持打开浏览器");
               }
            }
        }catch (Exception e) {
            System.err.println("打开浏览器异常：" + e.getMessage());
        }
    }
}
